<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .active {
        color: red;
      }
    </style>
  </head>
  <body>
    <div id="root"></div>
    <script src="./lib/react.js"></script>
    <script src="./lib/react_dom.js"></script>
    <script src="./lib/babel.js"></script>

    <script type="text/babel">
      class App extends React.Component {
        constructor() {
          super()
          this.state = {
            movies: ['abc', 'cba', 'nba', 'sba'],
            currentIndex: 0,
          }
        }

        liElClick(index) {
          this.setState({
            currentIndex: index,
          })
        }

        render() {
          const { movies, currentIndex } = this.state
          return (
            <div>
              <ul>
                {movies.map((item, index) => (
                  <li
                    key={item}
                    className={index === currentIndex ? 'active' : ''}
                    onClick={() => this.liElClick(index)}
                  >
                    {item}
                  </li>
                ))}
              </ul>
            </div>
          )
        }
      }

      const root = ReactDOM.createRoot(document.querySelector('#root'))
      root.render(<App />)
    </script>
  </body>
</html>
